﻿<%@ Page Title="" Language="C#" MasterPageFile="~/__Page.master" AutoEventWireup="true" CodeBehind="HotelDetail.aspx.cs" Inherits="simpleHotel.Web.HotelDetail" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="placeCenterContent" runat="server">
    <asp:ScriptManager ID="mscript" runat="server"></asp:ScriptManager>
    
    <script>
        arrDayName = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
    </script>

    <div class="check">
        <div class="content"><h3>Thông tin khách sạn</h3></div>
        <div>
            <table cellpadding="0" cellspacing="0" style="width:100%">
                <tr>
                    <td style="width:140px;"><img src="../Images/room-hotel.jpg" width="300" height="200" /></td>
                    <td valign="top" style="padding-left:10px">
                        <table cellpadding="0" cellspacing="0" style="width:100%">
                            <tr>
                                <td><b><asp:Label ID="lblHotelName" runat="server" Font-Size="13"></asp:Label></b>
                                    <asp:Label ID="lblHotelID" runat="server" Visible="false"></asp:Label>
                                </td>
                            </tr>
                             <tr>
                                <td style="font-size:13px;text-align:justify;padding-top:5px;padding-bottom:5px"><asp:Label ID="lblHotelDescription" runat="server"></asp:Label></td>
                            </tr>
                            <tr>
                                <td><a class="lnk" id="imgview" href="HotelImages.aspx?hotelid=<%=hid%>" title='<%=hname %>'>Hình ảnh</a></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
                    <script>
                        $(document).ready(function () {
                            $('#imgview').click(function () {
                                    var url = this.href;
                                    var dialog = $('<iframe src="' + url + '" frameborder="0" style="overflow: hidden;"></iframe>').appendTo('body');

                                    dialog.dialog({ modal: true, title: $('#imgview').attr('title'), width: 1000, height: 460, open: function (type, data) { $(this).parent().appendTo("form"); } });
                                    dialog.width('1000px');
                                    dialog.height('420px');
                                    return false;
                                });
                            });
                    </script>
        </div>

                    <script>
            var arrRoom = new Array();
            var arrPrice = new Array();
            var sum = 0;
        </script>

        <br /><br />
        <asp:Repeater ID="rpRooms" runat="server" OnItemCommand="rpRooms_ItemCommand">
            <ItemTemplate>
            <div style="margin-bottom:5px;font-size:13px;">
                <table style="width:100%;border: solid 1px #d1d1d1">
                    <tr>
                        <td style="width:20%"><asp:Label ID="lblRoomName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name")%>' Font-Bold="true"></asp:Label>
                            <asp:Label ID="lblRoomID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID")%>' Visible="false"></asp:Label>
                            <asp:Label ID="lblRoomCategory" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.RoomCategoryID")%>' Visible="false"></asp:Label>
                            <input type="hidden" id="txtHidData" runat="server" />
                        </td>
                        <td style="width:15%">
                            <a class="lnk" id='popupImgRoom<%# DataBinder.Eval(Container, "DataItem.ID")%>' href="HotelImages.aspx?hid=<%=hid%>&rid=<%# DataBinder.Eval(Container, "DataItem.RoomCategoryID")%>" title='<%# DataBinder.Eval(Container, "DataItem.Name")%>'>Hình ảnh</a>
                        </td>
                        <td style="width:15%">

                            <script>
                                var check<%# DataBinder.Eval(Container, "DataItem.ID")%> = '<%# CheckRoom(Int32.Parse(DataBinder.Eval(Container, "DataItem.HotelId").ToString()),Int32.Parse(DataBinder.Eval(Container, "DataItem.RoomCategoryId").ToString())) %>';
                                if (check<%# DataBinder.Eval(Container, "DataItem.ID")%> == 'True') {
                                    document.write("<a class='lnk' id='RoomPrice<%# DataBinder.Eval(Container, "DataItem.ID")%>' href='HotelPrice.aspx?hid=<%=hid%>&rid=<%# DataBinder.Eval(Container, "DataItem.RoomCategoryID")%>' title='Bảng giá phòng'>Giá phòng</a>");
                                }
                                else{
                                    document.write('<span>Giá phòng</span>');
                                }
                            </script>
                            
                            <asp:Label ID="lblPrice" runat="server" Visible="false" Text='<%# String.Format("{0:#,###}",DataBinder.Eval(Container, "DataItem.PricePerDay")) %>'></asp:Label>
                            <asp:Label ID="lblprice1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PricePerDay")%>' Visible="false"></asp:Label>
                        </td>
                        <td style="width:22%">Số phòng:&nbsp;
                            <asp:TextBox ID="txtNumberOfRoom" runat="server" Width="50" MaxLength="3" Enabled='<%# CheckRoom(Int32.Parse(DataBinder.Eval(Container, "DataItem.HotelId").ToString()),Int32.Parse(DataBinder.Eval(Container, "DataItem.RoomCategoryId").ToString())) %>'></asp:TextBox>
                        </td>
                        <td style="width:25%">Thành tiền: <span id="price_<%# ((RepeaterItem)Container).FindControl("txtNumberOfRoom").ClientID %>"></span></td>
                    </tr>
                    <tr><td colspan="5">&nbsp;</td></tr>
                    
                    <tr>
                        <td style="width:80%" colspan="4"><%# DataBinder.Eval(Container, "DataItem.Description")%></td>
                        
                        <td style="width:20%"><asp:Button ID="btnCheckIn" runat="server" CssClass="checkin-button" Enabled='<%# CheckRoom(Int32.Parse(DataBinder.Eval(Container, "DataItem.HotelId").ToString()),Int32.Parse(DataBinder.Eval(Container, "DataItem.RoomCategoryId").ToString())) %>' Text="Đặt phòng" /></td>
                    </tr>
                </table>
                <script>

                    $("#<%# ((RepeaterItem)Container).FindControl("btnCheckIn").ClientID %>").click(function () {
                        if ($('#<%# ((RepeaterItem)Container).FindControl("txtNumberOfRoom").ClientID %>').val() == '') {
                            alert('Vui lòng nhập số lượng phòng.');
                            return false;
                        }
                    });

                    
                    arrRoom[arrRoom.length] = '<%# ((RepeaterItem)Container).FindControl("txtNumberOfRoom").ClientID %>';
                    arrPrice[arrPrice.length] = '<%# ((RepeaterItem)Container).FindControl("lblPrice").ClientID %>';

                    $("#<%# ((RepeaterItem)Container).FindControl("txtNumberOfRoom").ClientID %>").keydown(function (event) {
                        // Allow: backspace, delete, tab, escape, and enter
                        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
                            // Allow: Ctrl+A
                            (event.keyCode == 65 && event.ctrlKey === true) ||
                            // Allow: home, end, left, right
                            (event.keyCode >= 35 && event.keyCode <= 39)) {
                            // let it happen, don't do anything
                            return;
                        }
                        else {
                            // Ensure that it is a number and stop the keypress
                            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
                                event.preventDefault();
                            }
                        }
                    });
                    
                    //
                    strHolidayDate<%# DataBinder.Eval(Container, "DataItem.ID")%> = '<%# DataBinder.Eval(Container, "DataItem.HolidayDate")%>';
                    strDate<%# DataBinder.Eval(Container, "DataItem.ID")%>='<%=arrDate%>';
                    strDayOrWeek<%# DataBinder.Eval(Container, "DataItem.ID")%> = '<%=arrDayOfWeek%>';

                    arrHolidayDate<%# DataBinder.Eval(Container, "DataItem.ID")%> = strHolidayDate<%# DataBinder.Eval(Container, "DataItem.ID")%>.split(';');
                    arrDate<%# DataBinder.Eval(Container, "DataItem.ID")%> = strDate<%# DataBinder.Eval(Container, "DataItem.ID")%>.split(';');
                    arrDayOfWeek<%# DataBinder.Eval(Container, "DataItem.ID")%> = strDayOrWeek<%# DataBinder.Eval(Container, "DataItem.ID")%>.split(';');

                    var arrGia<%# DataBinder.Eval(Container, "DataItem.ID")%> = ['<%# String.Format("{0:0.##}",DataBinder.Eval(Container, "DataItem.NormalCompany"))%>', '<%# String.Format("{0:0.##}",DataBinder.Eval(Container, "DataItem.WeekendCompany"))%>', '<%# String.Format("{0:0.##}",DataBinder.Eval(Container, "DataItem.HolidayCompany"))%>'];
                                                                                 
                                                                                 

                    

                    $("#<%# ((RepeaterItem)Container).FindControl("txtNumberOfRoom").ClientID %>").blur(function () { 
                        
                        var arrSpecial<%# DataBinder.Eval(Container, "DataItem.ID")%> = new Array();

                        var countHoliday<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;
                        var countNormal<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;
                        var countWeekend<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;

                        var priceHoliday<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;
                        var priceNormal<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;
                        var priceWeekend<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;

                        var sum<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;
                        var sumall<%# DataBinder.Eval(Container, "DataItem.ID")%> = 0;


                        for (i = 0; i < arrDate<%# DataBinder.Eval(Container, "DataItem.ID")%>.length; i++) {
                            for (j = 0; j < arrHolidayDate<%# DataBinder.Eval(Container, "DataItem.ID")%>.length; j++) {

                                if (arrDate<%# DataBinder.Eval(Container, "DataItem.ID")%>[i] == arrHolidayDate<%# DataBinder.Eval(Container, "DataItem.ID")%>[j]) {
                                    arrSpecial<%# DataBinder.Eval(Container, "DataItem.ID")%>[arrSpecial<%# DataBinder.Eval(Container, "DataItem.ID")%>.length] = i;
                                    countHoliday<%# DataBinder.Eval(Container, "DataItem.ID")%>++;
                                }
                            }
                        }
                        priceHoliday<%# DataBinder.Eval(Container, "DataItem.ID")%> = countHoliday<%# DataBinder.Eval(Container, "DataItem.ID")%> * arrGia<%# DataBinder.Eval(Container, "DataItem.ID")%>[2];

                        
                        // check ngay trong tuan
                        for (i = 0; i < arrDayOfWeek<%# DataBinder.Eval(Container, "DataItem.ID")%>.length; i++) {
                            for (j = 0; j < arrDayName.length; j++) {

                                if (arrDayOfWeek<%# DataBinder.Eval(Container, "DataItem.ID")%>[i] == arrDayName[j]) {

                                    var check = 0;
                                    for (k = 0; k < arrSpecial<%# DataBinder.Eval(Container, "DataItem.ID")%>.length; k++) {
                                        if (arrSpecial<%# DataBinder.Eval(Container, "DataItem.ID")%>[k] == i) {
                                            check = 1; break;
                                        }
                                    }

                                    if (check == 0) {
                                        countNormal<%# DataBinder.Eval(Container, "DataItem.ID")%>++;
                                    }
                                }

                            }
                            // check ngay cuoi tuan
                            if (arrDayOfWeek<%# DataBinder.Eval(Container, "DataItem.ID")%>[i] == "Saturday" || arrDayOfWeek<%# DataBinder.Eval(Container, "DataItem.ID")%>[i] == "Sunday") {

                                var check = 0;
                                for (k = 0; k < arrSpecial<%# DataBinder.Eval(Container, "DataItem.ID")%>.length; k++) {
                                    if (arrSpecial<%# DataBinder.Eval(Container, "DataItem.ID")%>[k] == i) {
                                        check = 1; break;
                                    }
                                }

                                if (check == 0) countWeekend<%# DataBinder.Eval(Container, "DataItem.ID")%>++;

                            }
                        }

                        priceNormal<%# DataBinder.Eval(Container, "DataItem.ID")%> = countNormal<%# DataBinder.Eval(Container, "DataItem.ID")%> * arrGia<%# DataBinder.Eval(Container, "DataItem.ID")%>[0];

                        priceWeekend<%# DataBinder.Eval(Container, "DataItem.ID")%> = countWeekend<%# DataBinder.Eval(Container, "DataItem.ID")%> * arrGia<%# DataBinder.Eval(Container, "DataItem.ID")%>[1];



                        sum<%# DataBinder.Eval(Container, "DataItem.ID")%> = priceNormal<%# DataBinder.Eval(Container, "DataItem.ID")%> + priceWeekend<%# DataBinder.Eval(Container, "DataItem.ID")%> + priceHoliday<%# DataBinder.Eval(Container, "DataItem.ID")%>;

                        sumall<%# DataBinder.Eval(Container, "DataItem.ID")%> = $("#<%# ((RepeaterItem)Container).FindControl("txtNumberOfRoom").ClientID %>").val() * sum<%# DataBinder.Eval(Container, "DataItem.ID")%>;

                        $('#price_<%# ((RepeaterItem)Container).FindControl("txtNumberOfRoom").ClientID %>').text((getRepString(sumall<%# DataBinder.Eval(Container, "DataItem.ID")%>)));

                        document.getElementById('<%# ((RepeaterItem)Container).FindControl("txtHidData").ClientID %>').value=sumall<%# DataBinder.Eval(Container, "DataItem.ID")%>;
                    });
                </script>
            </div>
            
                <script>
                    $(document).ready(function () {
                        $('#popupImgRoom<%# DataBinder.Eval(Container, "DataItem.ID")%>').click(function () {
                            var url = this.href;
                            var dialog = $('<iframe src="' + url + '" frameborder="0" style="overflow: hidden;"></iframe>').appendTo('body');
                           
                            dialog.dialog({ modal: true, title: $('#popupImgRoom<%# DataBinder.Eval(Container, "DataItem.ID")%>').attr('title'), width: 1000, height: 460, open: function (type, data) { $(this).parent().appendTo("form"); } });
                            dialog.width('1000px');
                            dialog.height('420px');
                            return false;
                        });
                    });
                </script>

                <script>
                    $(document).ready(function () {
                        $('#RoomPrice<%# DataBinder.Eval(Container, "DataItem.ID")%>').click(function () {
                            var url = this.href;
                            var dialog = $('<iframe src="' + url + '" frameborder="0" style="overflow: hidden;"></iframe>').appendTo('body');

                            dialog.dialog({ modal: true, title: $('#RoomPrice<%# DataBinder.Eval(Container, "DataItem.ID")%>').attr('title'), width: 800, height: 150, open: function (type, data) { $(this).parent().appendTo("form"); } });
                            dialog.width('800px');
                            dialog.height('150px');
                            return false;
                        });
                    });
                </script>
                    
            
        </ItemTemplate>
    </asp:Repeater>

        <div style="margin-bottom:5px">
                <!--<table style="width:100%;border: solid 1px #d1d1d1;font-size:13px">
                    <tr>
                        <td colspan="4"></td>
                        <td style="width:30%">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            Tổng: <span id='sum' style="font-weight:bold"></span></td>
                    </tr>
                </table>-->
        </div>

        <div style="margin-bottom:5px">
                <%--<table style="width:100%;border: solid 0px #d1d1d1" cellpadding="0" cellspacing="0">
                    <tr>
                        <td colspan="4"></td>
                        <td style="width:30%;text-align:right">
                            &nbsp;
                            <asp:Button ID="btnBook" runat="server" OnClick="btnSubmit_Click" Text="Đặt phòng" OnClientClick="return CheckRoomAmountValid()" />
                            <%--<telerik:RadButton ID="btnSubmit" Skin="Metro" Height="25px" Width="120px" BorderStyle="Solid" BorderColor="#d1d1d1"  runat="server" Text="Đặt phòng" OnClick="btnSubmit_Click" OnClientClick="return CheckRoomAmountValid()" />
                        </td>
                    </tr>
                </table>--%>
        </div>

        <script>

            function CalculatePrice() {
                var number = 0;
                var price = 0;
                sum = 0;
                for (i = 0; i < arrRoom.length; i++) {
                    number = $('#' + arrRoom[i]).val() * $('#' + arrPrice[i]).text().replace(',', '');
                   

                    //price = getRepString(number);
                    //$('#aaa').text(price);
                    
                    sum = sum + parseInt(number);
                    
                }
                //alert('hhh');
                $('#sum').text(getRepString(sum));
            }

            function getRepString(rep) {
                rep = rep + ''; // coerce to string
                var seperate = ',';
                if (rep < 1000) {
                    return rep; // return the same number
                } else if (rep < 1000000) { // place a comma between
                    return rep.substring(0, 3) + seperate + rep.substring(3, 6);
                } else if (rep < 10000000) { // place a comma between
                    return rep.charAt(0) + seperate + rep.substring(1, 4) + seperate + rep.substring(4, 7); //1250000
                }
                else if (rep < 100000000) { // place a comma between
                    return rep.substring(0, 2) + seperate + rep.substring(2, 5) + seperate + rep.substring(5, 8); //12500000
                }
            }


            function CheckNumberRoomInput(id) {
                alert(id);
                //if ($(id).val() == '')
                    //alert('Vui lòng nhập số lượng phòng.');
            }


            function CheckRoomAmountValid()
            {
                var selectedCount = 0;
                var element;
                var res = '';
                var flag=0;

                for (var i = 0; i < document.forms[0].elements.length; i++) {
                    element = document.forms[0].elements[i];

                    if (element.type == 'text' && element.disabled == false && element.value != '') {
                        flag = 1;
                        break;
                    }
                }

                if (flag == 0) {
                    alert('Vui lòng nhập số lượng phòng.');
                    return false;
                }
            }

        </script>

        

        <div id="popupImg"></div>
        <%--<iframe id='popupImg' width="800" height="600" frameborder="0" scrolling="no"></iframe>--%>

    </div>
    
</asp:Content>
